const service = require('../../utils/service.js')
const api = require('../../utils/util.js')
Page({
  data: {
    order_id: '',
    userInfo: '',
    goodsInfo: {}
  },

  onLoad: function (options) {
    let userInfo = wx.getStorageSync('userInfo')
    this.setData({
      order_id: options.order_id,
      userInfo: userInfo
    })
    this.init()
  },

  init: function () {
    // 退款商品信息
    let that = this
    api.ajax(service.url('orderDetail'), {
      unionid: that.data.userInfo.shop_unionid,
      order_id: that.data.order_id
    },
    function (res) {
      if (res.code == 0) {
        that.setData({
          goodsInfo: res.data
        })
      } else {
        api.toast(res.message)
      }
    })
  },

  // 前往退款、退货页面
  toRefun: function (e) {
    let type = e.currentTarget.dataset.type
    let order_id = this.data.order_id
    wx.navigateTo({
      url: `../refun/refun?type=${type}&order_id=${order_id}`,
    })
  }
})